package com.study.web.controller.app;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.study.app.domain.bo.AppUserAgreementBo;
import com.study.app.domain.vo.AppUserAgreementVo;
import com.study.app.service.IAppUserAgreementService;
import com.study.common.annotation.Log;
import com.study.common.annotation.RepeatSubmit;
import com.study.common.core.controller.BaseController;
import com.study.common.core.domain.PageQuery;
import com.study.common.core.domain.R;
import com.study.common.core.page.TableDataInfo;
import com.study.common.core.validate.EditGroup;
import com.study.common.enums.BusinessType;
import com.study.common.utils.poi.ExcelUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;

/**
 * App用户协议隐私条款维护
 *
 * @author magicyo
 * @date 2023-09-25
 */
@Validated
@RequiredArgsConstructor
@RestController

@RequestMapping("/system/userAgreement")
public class AppUserAgreementController extends BaseController {

    private final IAppUserAgreementService iAppUserAgreementService;

    /**
     * 查询App用户协议隐私条款维护列表
     */
    @SaCheckPermission("system:userAgreement:list")
    @GetMapping("/list")
    public TableDataInfo<AppUserAgreementVo> list(AppUserAgreementBo bo, PageQuery pageQuery) {
        return iAppUserAgreementService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出App用户协议隐私条款维护列表
     */
    @SaCheckPermission("system:userAgreement:export")
    @Log(title = "App用户协议隐私条款维护", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(AppUserAgreementBo bo, HttpServletResponse response) {
        List<AppUserAgreementVo> list = iAppUserAgreementService.queryList(bo);
        ExcelUtil.exportExcel(list, "App用户协议隐私条款维护", AppUserAgreementVo.class, response);
    }

    /**
     * 获取App用户协议隐私条款维护详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("system:userAgreement:query")
    @GetMapping("/{id}")
    public R<AppUserAgreementVo> getInfo(@NotNull(message = "主键不能为空")
                                         @PathVariable Long id) {
        return R.ok(iAppUserAgreementService.queryById(id));
    }

    /**
     * 新增App用户协议隐私条款维护
     */
    @SaCheckPermission("system:userAgreement:add")
    @Log(title = "App用户协议隐私条款维护", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated @RequestBody AppUserAgreementBo bo) {
        return toAjax(iAppUserAgreementService.insertByBo(bo));
    }

    /**
     * 修改App用户协议隐私条款维护
     */
    @SaCheckPermission("system:userAgreement:edit")
    @Log(title = "App用户协议隐私条款维护", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody AppUserAgreementBo bo) {
        return toAjax(iAppUserAgreementService.updateByBo(bo));
    }

    /**
     * 删除App用户协议隐私条款维护
     *
     * @param ids 主键串
     */
    @SaCheckPermission("system:userAgreement:remove")
    @Log(title = "App用户协议隐私条款维护", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(iAppUserAgreementService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
}

